package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Author likepei
 * @Date 2020/4/5 22:45
 * @Version v1.0
 * @Description 会员业务接口实现类
 */
@Service
@Slf4j
@Transactional
public class MemberServiceImpl implements MemberService {

    //依赖注入dao
    @Autowired
    private MemberDao memberDao;

    /**
     * 根据手机号获取会员信息
     * @param telephone
     */
    @Override
    public void smsLogin(String telephone) {
        //调用dao, 根据手机号码 查询会员信息
        Member member = memberDao.findByTelephone(telephone);
        //会员信息不为null, 说明会员已存在, 直接登录返回就好了
        if(member != null){
            //说明会员已存在, 不需要做任何操作, 直接登录 进入到首页
        } else {
            //说明会员不存在, 先进行会员注册, 再进入到首页
            member = new Member();
            member.setPhoneNumber(telephone);
            member.setRegTime(new Date());
            //调用dao, 存入新会员
            memberDao.add(member);
        }

    }
}
